<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <meta http-equiv="Cache-Control" content="no-cache" />
    <meta name="description" content="长沙市妇幼医院">
    <title>领取免费券</title>
    <link rel="stylesheet" href="css/fillInfo.css">
    <script src="./js/jquery.min.js"></script>
    <script src="js/jweixin-1.2.0.js" type="text/javascript" charset="utf-8"></script>
</head>
<script type="text/javascript">
    var openId = '';
    var idcardType = "";//免费类型
    $(document).ready(function(){
        var url = location.search.substr(1);
        var arr = url.split("&");
        openId = arr[0].split("=")[1];
//        alert(openId);
        $.ajax({
            method: 'POST',
            url: '/csfy/wx/getPresonInfo.do',
            data: {},
            success: function (res) {
//                alert("成功"+res)
                var getData = JSON.parse(res);
                if (getData.code == 200) {
                    var imgUrl = '';
                    if(getData.data.cardFrontImgUrl != null){//如果有身份证照片展示本人身份证照片，没有就展示居住证
                        imgUrl = getData.data.cardFrontImgUrl;
                    }else {
                        imgUrl = getData.data.residencePermitImgUrl;
                    }

                    //图片脱敏发起查看请求
                    $.ajax({
                        url:'/csfy/coupon/getPicForGc.do',
                        type:'GET',
                        data:{fileName:imgUrl},
                        dataType: 'json',
                        async:false,
                        success:function (data) {
                            $('.personImg').prop('src','data:'+'image/jpeg'+';base64,'+data);
                        }
                    });


                    idcardType = getData.data.presonType;
                    $(".userName").text(getData.data.name);
                    $(".userSex").text(getData.data.sex);
                    $(".nation").text(getData.data.nation);
                    $(".userId").text(getData.data.id);
                    $(".userAddress").text(getData.data.address);
                    $(".address").text(getData.data.country+getData.data.town);
                    var isChargeInfos = '';
                    var couponInfos = '';
                    var unreceivedCouponInfos = '';
                    var status = '';
                    //遍历已领取的优惠券
//                    alert("yi领取的列表长度："+getData.data.couponInfos.length)
                    if(getData.data.couponInfos.length > 0){
                        for(var i=0;i<getData.data.couponInfos.length;i++){
                            if(getData.data.couponInfos[i].type != 6 && getData.data.couponInfos[i].type != 3) {//屏蔽地贫和HPV
                                if(getData.data.couponInfos[i].isCharge != 2){
                                    if(getData.data.couponInfos[i].status == -1){
                                        status = "未审批通过";
                                    }else if(getData.data.couponInfos[i].status == 0){
                                        status = "审批中";
                                    }else if(getData.data.couponInfos[i].status == 1){
                                        status = "使用";
                                    }else if(getData.data.couponInfos[i].status == 2){
                                        status = "已使用";
                                    }else if(getData.data.couponInfos[i].status == 3){
                                        status = "已绑定";
                                    }
                                    if(getData.data.couponInfos[i].status == 1){
                                        couponInfos += '<li>' + '<img src="' + getData.data.couponInfos[i].couponImg + '" onclick="ewmInfo(' + "'" + getData.data.couponInfos[i].couponNum  + "'" + ',' +
                                                "'" + getData.data.couponInfos[i].status  + "'" + ',' + "'" + getData.data.couponInfos[i].type + "'" + ')"' + '>' +
                                                '<span class="span-bt"  onclick="goUrl(' + "'" + getData.data.couponInfos[i].type + "'" + ',' + "'" + getData.data.couponInfos[i].couponNum + "'" + ')">' + '使用' +'</span></li>';
                                    }else if(getData.data.couponInfos[i].status == -1){
                                        couponInfos += '<li>' + '<img src="' + getData.data.couponInfos[i].couponImg + '" onclick="return false"' + '>' +
                                                '<span>' + status +'</span></li>';
                                    }else {
                                        couponInfos += '<li><a onclick="ewmInfo(' + "'" + getData.data.couponInfos[i].couponNum  + "'" + ',' +
                                                "'" + getData.data.couponInfos[i].status  + "'" + ',' + "'" + getData.data.couponInfos[i].type + "'" + ')">' + '<img src="' + getData.data.couponInfos[i].couponImg +  '" onclick="return false"' + '></a>' +
                                                '<span>' + status +'</span></li>';
                                    }
                                }else {
                                    if(getData.data.couponInfos[i].status == -1){
                                        status = "未审批通过";
                                    }else if(getData.data.couponInfos[i].status == 0){
                                        status = "审批中";
                                    }else if(getData.data.couponInfos[i].status == 1){
                                        status = "使用";
                                    }else if(getData.data.couponInfos[i].status == 2){
                                        status = "已使用";
                                    }else if(getData.data.couponInfos[i].status == 3){
                                        status = "已绑定";
                                    }
                                    isChargeInfos += '<li><a onclick="ewmInfo(' + "'" + getData.data.couponInfos[i].couponNum  + "'" + ',' +
                                            "'" + getData.data.couponInfos[i].status  + "'" + ',' + "'" + getData.data.couponInfos[i].type + "'" + ')">' + '<img src="' + getData.data.couponInfos[i].couponImg +  '" onclick="return false"' + '></a>' +
                                            '<span>' + status +'</span></li>';
                                }
                            }
                        }
                        $(".couponList").append(couponInfos);
                        $(".isChargeList").append(isChargeInfos);
                    }
                    //遍历可领取的优惠券

//                    alert("未领取的列表长度："+getData.data.unreceivedCouponInfos.length)
                    if(getData.data.unreceivedCouponInfos.length > 0){
                        for(var i=0;i<getData.data.unreceivedCouponInfos.length;i++){
                            if(getData.data.unreceivedCouponInfos[i].type != 6 && getData.data.unreceivedCouponInfos[i].type != 3){//屏蔽地贫和HPV
                                unreceivedCouponInfos += '<li>' + '<img src="' + getData.data.unreceivedCouponInfos[i].couponImg + '" onclick="return false"' + '>' +
                                    '<span class="span-bt"  onclick="checkPush(' + "'" + getData.data.unreceivedCouponInfos[i].type + "'" + ')">' + '领取' +'</span></li>';
                            }
                        }
                        $(".underCouponList").append(unreceivedCouponInfos);
                    }
                }else {
                    alert(getData.msg);
                }
            },
            error:function (res) {
                alert(JSON.parse(res).msg);
            }
        })

    })
    //领券
    var quanType = '';
    function checkPush(type) {
        //点领券清空胎数和末次月经
        $(".taishu").val('');
        $(".lmp").val('');
        quanType = type;
//        alert(type);
        if(type == 1 || type == 5){
            $(".zhezhao").css("display","block");
            $(".lmpDiv").css("display","none");
            $(".alertDiv").css("display","block");
            $(".taishuDiv").css("display","inline-block");
        }
        if(type == 2 || type == 4 || type == 6){
            $(".zhezhao").css("display","block");
            $(".lmpDiv").css("display","block");
            $(".alertDiv").css("display","block");
            $(".taishuDiv").css("display","none");
        }
        if(type == 3){
            lingQuan(type);
        }
    }
//    var idcardType = localStorage.getItem('idcardType');
    function lingQuan(type) {
        if((type == 1 || type == 5) && $(".taishu option:selected").val() == ''){
            alert("请选择胎数");
            return false;
        }
        if((type == 2 || type == 4 || type == 6) && $(".lmp").val() == ''){
            alert("请输入末次月经时间");
            return false;
        }
        $.ajax({
            type: 'POST',
            async:false,
            url: '/csfy/wx/addCouponInfo.do',
            data: {
                type: type,
                num:$(".taishu option:selected").val(),
                lmp:$(".lmp").val()
            },
            success: function (res) {
//                alert(res);
                var getData = JSON.parse(res);
                if(getData.code == 200){
                    if(getData.rows == 0){
                        if(idcardType == 1){
                            alert("请您携带本人身份证、户口本、产检资料到本人户籍地所在的街道社区卫生服务中心/乡镇卫生院现场咨询。");
                            window.location.reload();
                        }else if(idcardType == 2){
                            alert("请您携带本人身份证、产检资料、结婚证、丈夫户口本和身份证到本人居住地（需办理居住证）或丈夫户籍地所在的街道社区卫生服务中心/乡镇卫生院现场咨询。");
                            window.location.reload();
                        }else if(idcardType == 3){
                            alert("请您携带本人身份证、户口本、产检资料到本人居住证所在的街道社区卫生服务中心/乡镇卫生院现场咨询。");
                            window.location.reload();
                        }
                    }else if(getData.rows == 1){
                        alert("领取成功");
                        window.location.href = "/csfy/user/couponList.html";
                    }
                }else{
                    alert(getData.msg);
                    window.location.href = "/csfy/user/couponList.html";
                }
            }, error: function (res) {
                alert(JSON.parse(res).msg);
            }
        })
    }
    //选择胎数或者末次月经时间确认
    function alertDivSubmit() {
        lingQuan(quanType);
    }
    //点击使用优惠券跳转到对应的送检单
    function goUrl(type,couponNum){
//        alert("type:"+type+"--------couponNum:"+couponNum)
        var arrUrl = ['/csfy/user/deaf_sheet.html',
                        '/csfy/user/nifty_sheet.html',
                        '/csfy/user/hpv_sheet.html',
                        '/csfy/user/preborn_sheet.html',
                        '/csfy/user/newborn_sheet.html',
                        '/csfy/user/dipin_sheet.html'];
        if(type == 1 || type == 2 || type == 5){
            let juanInfo = {
                type:type,
                couponNum:couponNum
            }
            sessionStorage.setItem('juanInfo',JSON.stringify(juanInfo));
            let num = type - 1;
            window.location.href = arrUrl[num];
        }else {
            alert('该产品暂不支持线上使用，请点击免费券图片展示二维码提供给现场医护人员');
        }
    }
    //点击显示已领取通过的优惠券二维码
    function ewmInfo(couponNum,status,type){
//        alert("couponNum:"+couponNum+"------status:"+status+"------type:"+type);
        if(couponNum != ""){
//            alert("idcardType:"+idcardType+"-----status:"+status)
            if(idcardType == 1 && status == 0){
                alert("请您携带本人身份证、户口本、产检资料到本人户籍地所在的街道社区卫生服务中心/乡镇卫生院现场咨询。");
                window.location.reload();
            }else if(idcardType == 2 && status == 0){
                alert("请您携带本人身份证、产检资料、结婚证、丈夫户口本和身份证到本人居住地（需办理居住证）或丈夫户籍地所在的街道社区卫生服务中心/乡镇卫生院现场咨询。");
                window.location.reload();
            }else if(idcardType == 3 && status == 0){
                alert("请您携带本人身份证、户口本、产检资料到本人居住证所在的街道社区卫生服务中心/乡镇卫生院现场咨询。");
                window.location.reload();
            }
            if(status == 0 || status == -1){//审批中不展示二维码
                return false;
            }
            if(status == 2 && type == 4){//产前血清 已使用状态不展示二维码
                return false;
            }
            $.ajax({
                url: "/csfy/getUrlBarcode.do",
                async:false,
                dataType:"json",
                data:{
                    "url":"checkQRUser.do?couponNum=" + couponNum
                },
                success: function (res) {
//                    alert("二维码"+JSON.stringify(res));
                    if(res.code == 200){
                        $(".erweima").attr("src",'data:image/jpg;base64,'+res.rows);
                        $(".erweima").css("display","block");
                        $(".zhezhao").css("display","block");
                    }
                },
                error:function (res) {
                    alert(res.msg)
                }
            });
        }else {
            alert("免费券编码不存在");
        }
    }
    //点击遮罩隐藏二维码
    function closeDiv() {
        $(".erweima").css("display","none");
        $(".zhezhao").css("display","none");
        $(".alertDiv").css("display","none");
    }
</script>
<body>
    <ul class="personInfo">
        <li>个人信息</li>
        <li>
            <img class="personImg" src="" alt="">
        </li>
        <li>
            <span class="span-left">姓　　名：</span><span class="userName span-right"></span>
        </li>
        <li>
            <span class="span-left">性　　别：</span><span class="userSex span-right"></span>
        </li>
        <li>
            <span class="span-left">民　　族：</span><span class="nation span-right"></span>
        </li>
        <li>
            <span class="span-left">证件号码：</span><span class="userId span-right"></span>
        </li>
        <li>
            <span class="span-left">地　　址：</span><span class="userAddress span-right"></span>
        </li>
        <li>
            <span class="span-left">所属街道：</span><span class="address span-right"></span>
        </li>
    </ul>
    <ul class="isChargeList">
        <li>自费券</li>
    </ul>
    <ul class="couponList">
        <li>已领取的免费券</li>
    </ul>
    <ul class="underCouponList">
        <li>未领取的免费券</li>
    </ul>
    <div class="zhezhao" onclick="closeDiv()"></div>
    <img class="erweima" src="" alt="">
    <ul class="alertDiv">
        <li class="taishuDiv">
            <span>胎　　数：</span>
            <select class="taishu">
                <option value="">请选择胎数</option>
                <option value="1">单胎</option>
                <option value="2">双胎</option>
                <option value="3">三胎</option>
            </select>
        </li>
        <li class="lmpDiv">
            <span>末次月经：</span>
            <input type="date" class="lmp">
        </li>
        <li>
            <span class="span-bt" onclick="alertDivSubmit()">确认</span>
        </li>
    </ul>
</body>

</html>